package com.joyd.joydlib.composables

import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.defaultMinSize
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import com.joyd.joydlib.ui.theme.JoydLibThemeExtensions

/**
 * JoydLib的自定义按钮控件
 * 提供了常用的按钮功能和样式定制选项
 *
 * @param text 按钮显示的文本
 * @param onClick 点击事件回调
 * @param modifier 修饰符
 * @param enabled 是否启用按钮
 * @param backgroundColor 按钮背景颜色，默认使用主题主色
 * @param contentColor 按钮文本颜色，默认使用主题主文本色
 */
@Composable
fun JoydButton(
    text: String,
    onClick: () -> Unit,
    modifier: Modifier = Modifier,
    enabled: Boolean = true,
    backgroundColor: Color = JoydLibThemeExtensions.colors.primary,
    contentColor: Color = JoydLibThemeExtensions.colors.onPrimary
) {
    Button(
        onClick = onClick,
        modifier = modifier
            .defaultMinSize(minWidth = 64.dp, minHeight = 40.dp),
        enabled = enabled,
        shape = RoundedCornerShape(8.dp),
        colors = ButtonDefaults.buttonColors(
            containerColor = backgroundColor,
            contentColor = contentColor,
            disabledContainerColor = JoydLibThemeExtensions.colors.primary.copy(alpha = 0.3f),
            disabledContentColor = JoydLibThemeExtensions.colors.onPrimary.copy(alpha = 0.3f)
        ),
        contentPadding = PaddingValues(horizontal = 16.dp, vertical = 8.dp)
    ) {
        Text(text = text)
    }
}